<!-- 订单 -->
<template>
	<view>
		<view class="order">
			<view class="order_card" v-for="(item, index) in order_card_list" :key="index"
				@click="goto('../subpages/order_state/order_state')">
				<ordercard :ordercardall="item" @deleteitem="deleteitem"></ordercard>
			</view>
		</view>
		<u-back-top :scroll-top="scrollTop" mode="square" tips="顶部"></u-back-top>
		<u-empty v-if="order_card_list.length==0" mode="order" class="isempty" iconSize="240rpx" font-size="40rpx">
		</u-empty>
	</view>
</template>
<script>
	import ordercard from '../components/ordercard/ordercard.vue'
	export default {
		components: {
			ordercard
		},
		data() {
			return {
				//回到顶部
				pageNumber: 0,
				scrollTop: 0,
				show: false,
				content: '你确定要删除吗？',
				order_card_list: [
					// {
					// 	index: '0',
					// 	state: '下单成功',
					// 	image: 'https://tse1-mm.cn.bing.net/th/id/OET.cb5938bcaa074d36834d4474a5446271?w=272&h=272&c=7&rs=1&o=5&dpr=1.25&pid=1.9',
					// 	name: '苹果',
					// 	price: '5',
					// 	address: '贵州省黔南布依族苗族自治州长顺县管顺镇石坂村马拜洞组',
					// 	deadline: '2021/12/02'
					// }
				],
				cardshow: 0
			}
		},
		methods: {
			//页面跳转
			goto(url) {
				uni.navigateTo({
					url: url,
					animationType: 'slide-in-right',
					animationDuration: 1000
				})
			},
			pushlist(list) {
				for (let i = 0; i < list.length; i++) {
					// 先转成字符串再转成对象，避免数组对象引用导致数据混乱
					// let item = JSON.parse(JSON.stringify(list[i]))
					// item.id = this.$u.guid();
					this.order_card_list.push(list[i]);
				}
			},
			deleteitem(uuid) {
				this.order_card_list = this.order_card_list.filter(item => {
					item.orderUuid != uuid
				})
			},
			async getData() {
				const res = await this.$myRequest({
					url: '/contractOrder/getOrderListPage',
					method: 'POST',
					data: {
						'pageNum': this.pageNumber,
						'pageSize': 10,
						'uStatus': 0
					}
				}).then((res) => {
					if (res.data.code == 200) {
						this.pushlist(res.data.data.records);
						this.pageNumber++;
					}
				});

			},
			showModal(index) {
				// console.log(index),
				this.show = true;
			},
			confirm(index) {
				//点击确定后响应删除
				this.order_list.splice(index, 1);
			}
		},

		onLoad() {
			this.getData();
		},
		onPageScroll(e) { //生命周期函数
			this.scrollTop = e.scrollTop
		},
		onReachBottom() { //到达底部
			this.getData();
		},
		onPullDownRefresh() {
			this.order_card_list = []
			this.pageNumber = 0
			this.getData()
		},
	}
</script>

<style>
	@import url("order.css");
</style>
